﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SweetSurvey.Models;
using SweetSurvey.Models.Repositories;

namespace SweetSurvey.Tests.RepositoryTests
{
    /// <summary>
    ///This is a test class for AnswerRepositoryTest and is intended
    ///to contain all AnswerRepositoryTest Unit Tests
    ///</summary>
    [TestClass()]
    public class AnswerRepositoryTest : RepositoryTestBase
    {
        #region Create Sample Data

        public static string CreateSampleAnswer(string optionId = null, string participatorId = null)
        {
            if (string.IsNullOrEmpty(optionId))
                optionId = OptionRepositoryTest.CreateSampleOption();

            if (string.IsNullOrEmpty(participatorId))
                participatorId = ParticipatorRepositoryTest.CreateSampleParticipator();

            return (new AnswerRepository()).Create(new Answer()
            {
                OptionId = optionId,
                ParticipatorId = participatorId
            });
        }

        #endregion

        /// <summary>
        ///A test for Create
        ///</summary>
        [TestMethod]
        public void CreateTest()
        {
            // prepare
            var id = CreateSampleAnswer();

            // assert
            Assert.IsFalse(string.IsNullOrEmpty(id));
        }

        /// <summary>
        ///A test for Delete
        ///</summary>
        [TestMethod]
        public void DeleteTest()
        {
            // prepare
            var id = CreateSampleAnswer();
            var repository = new AnswerRepository();

            // act
            repository.Delete(id);
            
            // assert
            try { repository.Get(id); Assert.Fail(); }
            catch (Exception) { }
        }
    }
}
